package com.hangzhou.xyj.ui.widget;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.hangzhou.xyj.R;

/**
 * 数据loading加载对话框控件
 *
 * @author neo.duan
 */
public class VisualizerView extends RelativeLayout {

    private Context mContext;
    private LayoutInflater inflater;
    private LayoutParams lp;
    private ImageView mIvAnim;
    private AnimationDrawable mAnimation;

    public VisualizerView(Context context) {
        super(context);
        this.mContext = context;

        View.inflate(context,R.layout.layout_visualizer_view, this);
        mIvAnim = (ImageView) findViewById(R.id.iv_visualizer_anim);
        // 通过ImageView对象拿到背景显示的AnimationDrawable
        mAnimation = (AnimationDrawable) mIvAnim.getDrawable();
    }

    /**
     * 开始动画
     */
    public void startAnim() {
        // 为了防止在onCreate方法中只显示第一帧的解决方案之一
        mIvAnim.post(new Runnable() {
            @Override
            public void run() {
                mAnimation.start();
            }
        });
    }

    //TODO 测试，正常播放需删除
    @Override
    public void onWindowFocusChanged(boolean hasWindowFocus) {
        super.onWindowFocusChanged(hasWindowFocus);
//        startAnim();
    }

    public void stopAnim() {
        mAnimation.stop();
    }
}